//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ruoyi.web.controller.user;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.live.app.service.CacheService;
import com.ruoyi.live.base.domain.*;
import com.ruoyi.live.base.domain.vo.TaskParam;
import com.ruoyi.live.base.mapper.LiveExamMapper;
import com.ruoyi.live.base.mapper.TaskMapper;
import com.ruoyi.live.configuration.SessionInfo;
import com.ruoyi.live.configuration.SessionName;
import com.ruoyi.live.tool.utils.Message;
import com.ruoyi.live.tool.utils.PageTotalResult;
import com.ruoyi.live.user.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.Nullable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import jakarta.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping({"/teacher"})
public class TeacherController extends BaseController {
    @Autowired
    TeacherService service;
    @Autowired
    CacheService cacheService;
    @Autowired
    TaskMapper taskDao;
    @Autowired
    LiveExamMapper examDao;

    public TeacherController() {
    }

    @RequestMapping({"/score"})
    @PreAuthorize("@ss.hasAnyRoles('admin,teacher')")
    public ModelAndView score() {
        return (new ModelAndView("teacher/teacher_score")).addObject("channel", this.service.getChannel());
    }

    @RequestMapping({"/teacherClassList"})
    public ModelAndView teacherClassList() {
        return new ModelAndView("teacher/teacher_class_list");
    }

    @RequestMapping({"/taskList"})
    @PreAuthorize("@ss.hasAnyRoles('admin,teacher')")
    public ModelAndView teacherTaskList(@Nullable Task entity) {
        return (new ModelAndView("teacher/teacher_task_list")).addObject("list", this.service.getTaskList(entity));
    }

    @RequestMapping({"/teacherClassUserImport"})
    public ModelAndView teacherClassUserImport() {
        return new ModelAndView("teacher/teacher_class_user_import_list");
    }

    @RequestMapping({"/teacherClassStudent"})
    public ModelAndView teacherClassStudent() {
        return new ModelAndView("teacher/teacher_class_student_list");
    }

    @ResponseBody
    @RequestMapping({"/SystemClassController/queryClass"})
    @PreAuthorize("@ss.hasAnyRoles('admin,teacher')")
    public TableDataInfo queryClass(SystemClass entity) {
        this.startPage();
        List<SystemClass> list = this.service.queryClass(entity);
        return this.getDataTable(list);
    }

    @ResponseBody
    @RequestMapping({"/SystemClassController/queryAllClass"})
    @PreAuthorize("@ss.hasAnyRoles('admin,teacher')")
    public TableDataInfo queryAllClass() {
        List<SystemClass> list = this.service.queryAllClass();
        return this.getDataTable(list);
    }

    @ResponseBody
    @RequestMapping({"/UserController/query"})
    @PreAuthorize("@ss.hasAnyRoles('admin,teacher')")
    public TableDataInfo query(User entity) throws Exception {
        this.startPage();
        List<User> list = this.service.query(entity);
        return this.getDataTable(list);
    }

    @RequestMapping({"/getTaskDetail/{id}"})
    @PreAuthorize("@ss.hasAnyRoles('teacher')")
    public ModelAndView getTaskDetail(@PathVariable Long id) {
        return (new ModelAndView("/teacher/task_detail")).addObject("task", this.cacheService.getTaskDetail(id));
    }

    @RequestMapping({"/teacherStudentList"})
    public ModelAndView teacherStudentList() {
        return new ModelAndView("teacher/teacher_class_student_list");
    }

    @RequestMapping({"/createStudent"})
    public ModelAndView teacherCreateStudent() {
        return new ModelAndView("teacher/teacher_create_student");
    }

    @ResponseBody
    @RequestMapping({"/addStudents"})
    @PreAuthorize("@ss.hasAnyRoles('admin,teacher')")
    public Message addStudents(Integer count, String firstName, Long classId) {
        try {
            this.service.addStudents(count, firstName, classId);
            return new Message(true, "生成成功");
        } catch (Exception var5) {
            var5.printStackTrace();
            return new Message(false, var5.getMessage());
        }
    }

    @RequestMapping({"/center"})
    @PreAuthorize("@ss.hasAnyRoles('admin,teacher')")
    public ModelAndView center() {
        Map<String, Integer> datas = this.service.getIndexDatas();
        List<Map<String, Object>> todos = this.service.getTodos();
        return (new ModelAndView("/teacher/teacher_center")).addObject("datas", datas).addObject("maxs", this.service.getMaxs()).addObject("avgs", this.service.getAvgs()).addObject("todos", todos).addObject("todoCount", todos.size());
    }

    @RequestMapping({"/teacherFxRecord"})
    @PreAuthorize("@ss.hasAnyRoles('admin,teacher')")
    public ModelAndView teacherFxRecord() {
        return (new ModelAndView("/teacher/teacher_fx_record")).addObject("datas", this.service.getDatas());
    }

    @RequestMapping({"/tj/bar"})
    @PreAuthorize("@ss.hasAnyRoles('admin,teacher')")
    @ResponseBody
    public Map<String, Object> bar() {
        return this.service.getBarDatas();
    }

    @RequestMapping({"/tj/scatter"})
    @PreAuthorize("@ss.hasAnyRoles('admin,teacher')")
    @ResponseBody
    public Map<String, Object> scatter() {
        return this.service.scatter();
    }

    @RequestMapping({"/fx/line"})
    @PreAuthorize("@ss.hasAnyRoles('admin,teacher')")
    @ResponseBody
    public Map<String, Object> line(TaskUserRecord record) {
        return this.service.line(record);
    }

    @RequestMapping({"/fx/toList"})
    @ResponseBody
    public String toList(TaskUserRecord record) {
        return "/student/mm_student_task_record_list";
    }

    @RequestMapping({"/fx/listDatas"})
    @PreAuthorize("@ss.hasAnyRoles('admin,teacher')")
    @ResponseBody
    public PageTotalResult listDatas(TaskUserRecord record) {
        return this.service.listDatas(record);
    }

    @RequestMapping({"/teacherFxRecordTask"})
    @PreAuthorize("@ss.hasAnyRoles('admin,teacher')")
    public ModelAndView listTeacherTaskFx(@Nullable TaskParam param) {
        return (new ModelAndView("/teacher/teacher_fx_task")).addObject("list", this.service.getTasksFx(param));
    }

    @RequestMapping({"/teacherFxRecordTaskDetail"})
    @PreAuthorize("@ss.hasAnyRoles('admin,teacher')")
    public ModelAndView teacherFxRecordTaskDetail(Long id) {
        return (new ModelAndView("/teacher/teacher_fx_task_detail")).addObject("obj", this.service.getTasksFxDetail(id));
    }

    @RequestMapping({"/fx/list/student/task"})
    @PreAuthorize("@ss.hasAnyRoles('admin,teacher')")
    @ResponseBody
    public TableDataInfo fxListStudentTask(Task entity) {
        this.startPage();
        return this.getDataTable(this.service.fxListStudentTask(entity));
    }

    @RequestMapping({"/teacherFxRecordStudent"})
    public ModelAndView teacherFxRecordStudent() {
        return (new ModelAndView("/teacher/teacher_fx_task_user")).addObject("allCount", this.taskDao.selectCount((Wrapper)null));
    }

    @RequestMapping({"/fx/student/query"})
    @PreAuthorize("@ss.hasAnyRoles('admin,teacher')")
    @ResponseBody
    public TableDataInfo fxColumnStudentTask(Task entity, HttpServletRequest request) {
        this.startPage();
        return this.getDataTable(this.service.fxColumnStudentTask(entity));
    }

    @RequestMapping({"/teacherFxRecordStudentDetail"})
    @PreAuthorize("@ss.hasAnyRoles('admin,teacher')")
    public ModelAndView teacherFxRecordStudentDetail(Long id, Integer count, Integer allCount) {
        return (new ModelAndView("/teacher/teacher_fx_task_user_detail")).addObject("datas", this.service.getUserDetail(id, count, allCount)).addObject("list", this.service.getUserDetailList(id));
    }

    @RequestMapping({"/class/check"})
    @PreAuthorize("@ss.hasAnyRoles('admin,teacher')")
    public ModelAndView classCheck() {
        return (new ModelAndView("/teacher/teacher_check_class")).addObject("clses", this.service.getClses()).addObject("clsId", SessionInfo.getClassId());
    }

    @RequestMapping({"/expertIndex"})
    public ModelAndView expertIndex() {
        List<LiveExam> exams = this.examDao.selectList((Wrapper)null);
        return (new ModelAndView("/expert/index")).addObject("user", SessionInfo.getUser()).addObject("exam", exams.get(0));
    }

    @RequestMapping({"/returnList"})
    public ModelAndView returnList() {
        SystemClass sc = (SystemClass) SessionInfo.get(SessionName.Cls);
        return (new ModelAndView("teacher/index")).addObject("user", SessionInfo.getUser()).addObject("className", sc.getClassName());
    }

    @RequestMapping({"/changeClass"})
    @PreAuthorize("@ss.hasAnyRoles('admin,teacher')")
    @ResponseBody
    public Message changeClass(Long id) {
        try {
            this.service.changeClass(id);
            return new Message(true, "切换成功");
        } catch (Exception var3) {
            var3.printStackTrace();
            return new Message(false, "切换失败");
        }
    }
}
